/* Simple JavaScript Tween v 0.2  - http://mattshaw.org/projects/simple-javascript-tweening 
 * 
 * [Arguments]
 * o: Target element
 * props: key/values object of props to tween
 * durationSecs: duration of tween in seconds (not millis)
 * onComplete: (optional) function to fire when tween is complete
 * easef: (optional) easing function
 */
(function(window){
	function MSTween(){};
	MSTween.tween = function (o,props,durationSecs,onComplete,onUpdate,easef){
		var fps=60,count=0,stopAt = fps*durationSecs,startVals={},endVals={},easef=easef||Quad_easeOut;
		for (var p in props) startVals[p] = tween_getProperty(o,p);
		for (var p in props) endVals[p] = props[p];
		var f=function(){
			count++;
			if (count>=stopAt){
				tween_stop(o);
				tween_setProps(o,endVals);
				if (onComplete) onComplete();
			} else {
				for (var p in props) {tween_setProperty(o,p, easef(count,startVals[p],endVals[p]-startVals[p],stopAt) )};
				if(onUpdate) onUpdate();
			}
		}
		clearInterval(o._tween_int);
		o._tween_int = setInterval(f,(1000)/fps);
	}
	tween_stop = function (o){ clearInterval(o._tween_int); }
	tween_setProps = function (o,props){ for (var p in props) tween_setProperty(o,p,props[p]); }
	tween_setProperty = function (o,p,value){ o[p]=value;}
	tween_getProperty = function (o,p){
		return o[p];
	}
	//R.Penner Quart easing t=time,b=start,c=delta,d=duration
	Quad_easeIn = function  (t, b, c, d) { return c*(t/=d)*t*t*t + b;}
	Quad_easeOut = function  (t, b, c, d) {	return -c * ((t=t/d-1)*t*t*t - 1) + b;}
	Quad_easeInOut = function  (t, b, c, d) { if ((t/=d/2) < 1) return c/2*t*t*t*t + b; return -c/2 * ((t-=2)*t*t*t - 2) + b; }
	if(!window.MSTween) window.MSTween = MSTween;
}(window))